import Vue from 'vue'
import Router from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import DlLogin from '../components/Login.vue'
import DlHome from '../components/Home.vue'

Vue.use(Router)

// const routes = [

// ]

 const router=new Router({
  routes: [{
      path: "/",
      redirect: "/login"
    },
    {
      path: '/login',
      component: DlLogin
    },
    {
      path: '/home',
      component: DlHome
    }
  ]
})

// 挂着路由导航守卫
router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next()
 var tokenStr= window.sessionStorage.getItem('token')
 if(!tokenStr){
   return next('/login')
 }
 next()
})

export default router